package com.dq;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

/**
 * @ClassName AbstractCondition
 * @Description 虚拟的Condition 根据传入的Classpath 找到是否
 * @Author DuX1aoQiang
 * @Date 2023/5/20 20:10
 * @Version 1.0
 */
public class AbstractCondition implements Condition {
    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata metadata) {
        try {
            Map<String, Object> map = metadata.getAnnotationAttributes(ConditionOnClass.class.getName());
            String className = (String) map.get("value");
            conditionContext.getClassLoader().loadClass(className);
            return true;
        } catch (ClassNotFoundException e) {
            return false;
        }
    }
}
